package gb.main;

import gb.Algorithm;
import gb.PolySet;
import gb.SPoly;
import gb.Utils;
import gb.ord.GradedOrd;
import gb.ord.LexOrd;
import gb.struct.Monomial;
import gb.struct.Polynomial;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        PolySet mySet = init4();
        System.out.println("my set: " + mySet);
        Polynomial g = getPoly2();
        System.out.println("poly to reduce: " + g);
        
        Polynomial result = Utils.normalForm(g, mySet);
        System.out.println("result: " + result);
        
        System.out.println("spoly on my set: " + SPoly.compute(mySet.getPoly(0), mySet.getPoly(1)));
        
    	mySet = init3();
        System.out.println("grobner set: " + Algorithm.run(mySet));
    }
    
    public static PolySet init() {
        PolySet set = new PolySet(2); //we have variables x, y (or x1, x2)
        
        Polynomial f1 = new Polynomial(new GradedOrd());
        Monomial temp = new Monomial(1);
        temp.addPower(1);
        temp.addPower(2);
        f1.addMono(temp);
        
        temp = new Monomial(-1);
        temp.addPower(1);
        temp.addPower(0);
        f1.addMono(temp);
        set.addPoly(f1);
        
        f1 = new Polynomial(new GradedOrd());
        f1.setComp(new GradedOrd());
        temp = new Monomial(1);
        temp.addPower(1);
        temp.addPower(0);
        f1.addMono(temp);
        
        temp = new Monomial(-1);
        temp.addPower(0);
        temp.addPower(3);
        f1.addMono(temp);
        set.addPoly(f1);
        
        return set;
    }

    
    public static Polynomial getPoly() {
        Polynomial g = new Polynomial(new GradedOrd());
        
        Monomial temp = new Monomial(1);
        temp.addPower(7);
        temp.addPower(2);
        g.addMono(temp);
        
        temp = new Monomial(1);
        temp.addPower(3);
        temp.addPower(2);
        g.addMono(temp);
        
        temp = new Monomial(-1);
        temp.addPower(0);
        temp.addPower(1);
        g.addMono(temp);
        
        temp = new Monomial(1);
        temp.addPower(0);
        temp.addPower(0);
        g.addMono(temp);
        
        return g;
    }
    
    public static PolySet init2() {
        PolySet set = new PolySet(3); //we have variables x, y (or x1, x2)
        //set.setComp(new LexOrd());
        
        Polynomial p = new Polynomial(new LexOrd());
        Monomial m = new Monomial(4);
        
        m.addPower(2);
        m.addPower(0);
        m.addPower(1);
        p.addMono(m);
        
        m = new Monomial(-7);
        m.addPower(0);
        m.addPower(2);
        m.addPower(0);
        p.addMono(m);
        set.addPoly(p);
        
        p = new Polynomial(new LexOrd());
        m = new Monomial(1);
        m.addPower(1);
        m.addPower(1);
        m.addPower(2);
        p.addMono(m);
        
        m = new Monomial(3);
        m.addPower(1);
        m.addPower(0);
        m.addPower(4);
        p.addMono(m);
        set.addPoly(p);
        
        return set;
    }

    public static PolySet init3() {
        PolySet set = new PolySet(3); //we have variables x, y (or x1, x2)
        //set.setComp(new LexOrd());
        
        Polynomial p = new Polynomial(new LexOrd());
        Monomial m = new Monomial(1);
        
        m.addPower(2);
        m.addPower(0);
        m.addPower(0);
        p.addMono(m);
        
        m = new Monomial(1);
        m.addPower(0);
        m.addPower(2);
        m.addPower(0);
        p.addMono(m);
        
        m = new Monomial(1);
        m.addPower(0);
        m.addPower(0);
        m.addPower(2);
        p.addMono(m);
        
        m = new Monomial(-1);
        m.addPower(0);
        m.addPower(0);
        m.addPower(0);
        p.addMono(m);
        set.addPoly(p);

        p = new Polynomial(new LexOrd());
        m = new Monomial(1);
        
        m.addPower(2);
        m.addPower(0);
        m.addPower(0);
        p.addMono(m);
        
        m = new Monomial(1);
        m.addPower(0);
        m.addPower(2);
        m.addPower(0);
        p.addMono(m);
        set.addPoly(p);
        
        m = new Monomial(1);
        m.addPower(0);
        m.addPower(0);
        m.addPower(2);
        p.addMono(m);
        
        m = new Monomial(-2);
        m.addPower(1);
        m.addPower(0);
        m.addPower(0);
        p.addMono(m);
        set.addPoly(p);
        
        p = new Polynomial(new LexOrd());
        m = new Monomial(2);
        
        m.addPower(1);
        m.addPower(0);
        m.addPower(0);
        p.addMono(m);
        
        m = new Monomial(-3);
        m.addPower(0);
        m.addPower(1);
        m.addPower(0);
        p.addMono(m);
        set.addPoly(p);
        
        m = new Monomial(-1);
        m.addPower(0);
        m.addPower(0);
        m.addPower(1);
        p.addMono(m);
        
        return set;
    }
    
    public static PolySet init4()
    {
    	PolySet set = new PolySet(2);
    	//set.setComp(new LexOrd());
        
        Polynomial p = new Polynomial(new LexOrd());
        Monomial m = new Monomial(1);
        
        m.addPower(1);
        m.addPower(1);
        p.addMono(m);
        
        m = new Monomial(-2);
        m.addPower(1);
        m.addPower(0);
        p.addMono(m);
        set.addPoly(p);
        
        p = new Polynomial(new LexOrd());
        m = new Monomial(2);
        m.addPower(2);
        m.addPower(0);
        p.addMono(m);
        
        m = new Monomial(-1);
        m.addPower(0);
        m.addPower(2);
        p.addMono(m);
        set.addPoly(p);
    	
    	return set;
    }
    
    public static Polynomial getPoly2() {
    	Polynomial p = new Polynomial(new LexOrd());
    	
    	Monomial m = new Monomial(1);
        m.addPower(3);
        m.addPower(2);
        p.addMono(m);
        
        m = new Monomial(3);
        m.addPower(2);
        m.addPower(1);
        p.addMono(m);
        
        m = new Monomial(-5);
        m.addPower(0);
        m.addPower(1);
        p.addMono(m);
        
        return p;
    }
}

